<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //unshift push shift pop splice concat join split  	
        //forEach()  map find fineIndex some every filters
            
        //数组的遍历 for for..in forEach  map

        /*
        var arr = [12,32,44,55,41];
        var obj = {name: 'libai', age: 45};

        for (const i in arr) {
            console.log(i, arr[i]);
        }
        
        // 只能遍历数组 ，不可以遍历对象
        arr.forEach(function (ele, index) {
            console.log(ele, index);
        });

        arr.forEach((ele, index) => {
            console.log(ele, index);
        })

        // 遍历数组，返回一个新数组，原数组不变
        var newArr = arr.map(function (ele, index) {
            return ele + 1
        })
        console.log(newArr);
        */

        var goods=[
            {
                id:100,
                good:'八喜',
                num:2,
                price:32
            },
            {
                id:101,
                good:'冰雪皇后',
                num:2,
                price:28
            },
            {
                id:105,
                good:'汉根达斯',
                num:1,
                price:60
            },
            {
                id:109,
                good:'蒙牛',
                num:10,
                price:3
            }
        ]               

	    /*
        // 去查找数组中的每一项，匹配成功成功返回具体某一项，如果找不到返回undefined
        var item = goods.find(function (el) {
            return el.id == 101
        })
        console.log(item);
        var item = goods.find(el => el.id == 101)
        console.log(item);

		// 去查找数组中的每一项，匹配成功成功返回下标，如果找不到返回-1
        var index = goods.findIndex(el => el.id == 101)
        goods.splice(index, 1)
        console.log(goods);
        */

        // filter some every reduce
        /*
		// 筛选数组，把符合的每一项放在数组中并返回新数组
        var newArr = arr.filter(el => el > 44)
        console.log(newArr);

	    // some:查找数组的每一项，只要有一项符合条件就返回true，全部不符条件返回false		
        var pp = arr.some(el => el > 44);
        console.log(pp);

	    //every:查找数组的每一项，全部符合条件返回true，只要有一个不符条件就返回false	
        var aa = arr.every(el => el > 33);
        console.log(aa);

        var arr2=[100,101,102,103];
        // reduce() 方法接收一个函数作为累加器，数组中的每个值（从左到右）开始缩减，最终计算为一个值。
        // 不带 初始值
        var some = arr2.reduce((pre, next) => {
            console.log(pre, '======', next);
            return pre + next;
        })
        console.log(some);
        // 带初始值
        var all = arr2.reduce((pre, next) => {
            console.log(pre, next);
            return pre - next
        }, 1000)
        console.log(all);

        var total = goods.reduce((count, val) => {
            return count + val.num * val.price
        }, 0)
        console.log(total);
        */

        //Array.from()     把伪数组转化为真正的数组
		//Array.isArray()  判断是否是数组 true/false

        function fun(a, b, c) {
            console.log(arguments.length);
            console.log(Array.from(arguments).push(4));
            console.log(Array.isArray(Array.from(arguments)));
        }
        fun(1, 2, 3)

        // 伪数组
        var obj = {
            0: 1,
            1: 2,
            2: 3,
            length: 3
        }
        // console.log(obj[1]);
        // console.log(Array.from(obj));

        var arr = [1, 2];
        // console.log(arr.push());

        var arr1 = new Array(3); 
        var arr2 = new Array('3');
        var arr3 = new Array(2, 3);
        console.log(arr1); // [empty] * 3
        console.log(arr2); // ['3']
        console.log(arr3); // [2, 3]

        var arr4 =Array.of(3);
        var arr5 =Array.of('3');
        var arr6 =Array.of(2, 3);
        console.log(arr4);
        console.log(arr5);
        console.log(arr6);
    </script>
</body>
</html>